package org.to_zero.springboot.springbootquick.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Enumeration;
import java.util.ResourceBundle;

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        ResourceBundle rb = ResourceBundle.getBundle("view");
        Enumeration<String> keys = rb.getKeys();
        while (keys.hasMoreElements()) {
            String path = keys.nextElement();
            String view = rb.getString(path);
            registry.addViewController(path).setViewName(view);
        }
    }

    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }
}
